<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="Generator" content="EditPlus®">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta name="renderer" content="webkit">
    <meta content="歪秀购物, 购物, 大家电, 手机" name="keywords">
    <meta content="歪秀购物，购物商城。" name="description">
    <title>修改邮箱</title>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/myFile/imgold/icon/favicon.ico}">
    <link rel="stylesheet" type="text/css" th:href="@{/theme/css/base.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/theme/css/member.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/laydate/theme/default/laydate.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/theme/css/home.css}">
    <script th:src="@{/theme/js/jquery-3.1.1.min.js}"></script>
    <script th:src="@{/laydate/laydate.js}"></script>
    <script th:src="@{/layui/layui.all.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/delCartOnPages.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/searchToPage.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/aes.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/jsencrypt.min.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/pad-zeropadding.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/security.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/random.js}"></script>
    <script type="text/javascript" th:src="@{/theme/js/encrypt/sendEncrypt.js}"></script>

    <script type="text/javascript">
          $(document).ready(function () {
              var data = $("#cartIdNull").val();
            $("#test").mouseover(function () {
                if(data=='notNull'){
                    layer.open({
                        type: 2,
                        title: '我的购物车',
                        shadeClose: true,
                        area: ['19%','60%'],
                        offset: ['9%', '76%'],
                        content: '/cart?pageNum=1&pageSize=100', //iframe的url
                    });
                }else{
                    layer.open({
                        type: 2,
                        title: '我的购物车',
                        shadeClose: true,
                        area: ['20%','20%'],
                        offset: ['9%', '76%'],
                        content: '/cart?pageNum=1&pageSize=100', //iframe的url
                    });
                }
            });

        });

function logout() {
    $.ajax({
        url: "/user/logout",
        dataType: "json",
        data: {},
        async: false,
        success: function (data) {
            if (data["result"] == "ok") {
                layer.msg('退出成功', {time: 1000}, function () {
                    window.location="index" ;
                });
            } else if (data["result"] == "fail") {
                layer.msg('您还没有登录哦~', {time: 1000}, function () {
                    window.location.reload();
                });
            }
        },
        type: "post"
    });
}
        (function (a) {
            a.fn.hoverClass = function (b) {
                var a = this;
                a.each(function (c) {
                    a.eq(c).hover(function () {
                        $(this).addClass(b)
                    }, function () {
                        $(this).removeClass(b)
                    })
                });
                return a
            };
        })(jQuery);

        $(function () {
            $("#pc-nav").hoverClass("current");
            var email = "[[${email}]]"
            if (email != "unexit") {
                hasEmailInit();
            }else {
                unhasEmailInit();
            }
        });

        function hasEmailInit() {
            $("#changeHtml").html('<div class="layui-form-item">\n' +
                '                                    <label class="layui-form-label">当前邮箱：</label>\n' +
                '                                    <div class="layui-input-block">\n' +
                '                                        <input type="text" name="title" th:value="" id="oldEmail" disabled required  lay-verify="required" autocomplete="off" class="layui-input">\n' +
                '                                    </div>\n' +
                '                                </div>\n' +
                '\n' +
                '                                <div class="layui-form-item">\n' +
                '                                    <label class="layui-form-label">验证码：</label>\n' +
                '                                    <div class="layui-input-inline">\n' +
                '                                        <input type="text" name="password" id="oldCode" required lay-verify="required"\n' +
                '                                               placeholder="请输入验证码" autocomplete="off" class="layui-input">\n' +
                '                                    </div>\n' +
                '                                    <button type="button" class="layui-btn layui-btn-primary" onclick="sendOldEmail()">获取验证码</button>\n' +
                '                                </div>\n' +
                '                                <div class="layui-form-item">\n' +
                '                                    <div class="layui-input-block">\n' +
                '                                        <button type="button" style="float: right" class="layui-btn layui-btn-primary" onclick="btn_next()">下一步\n' +
                '                                        </button>\n' +
                '                                    </div>\n' +
                '                                </div>');
        $("#oldEmail").val("[[${email}]]");

        }

        function unhasEmailInit() {
            $("#changeHtml").html('<div class="layui-form-item">\n' +
                '                                    <label class="layui-form-label">邮箱：</label>\n' +
                '                                    <div class="layui-input-block">\n' +
                '                                        <input type="text" name="password" id="newEmail"  required lay-verify="required"\n' +
                '                                               placeholder="请输入新邮箱" autocomplete="off" class="layui-input">\n' +
                '                                    </div>\n' +
                '                                </div>\n' +
                '\n' +
                '                                <div class="layui-form-item">\n' +
                '                                    <label class="layui-form-label">验证码：</label>\n' +
                '                                    <div class="layui-input-inline">\n' +
                '                                        <input type="text" name="password" id="newCode" required lay-verify="required"\n' +
                '                                               placeholder="请输入验证码" autocomplete="off" class="layui-input">\n' +
                '                                    </div>\n' +
                '                                    <button type="button" class="layui-btn layui-btn-primary" onclick="sendNewEmail()">获取验证码</button>\n' +
                '                                </div>\n' +
                '                                <div class="layui-form-item">\n' +
                '                                    <div class="layui-input-block">\n' +
                '                                        <button type="button" style="float: right" class="layui-btn layui-btn-primary" onclick="commit()">提交\n' +
                '                                        </button>\n' +
                '                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>\n' +
                '                                    </div>\n' +
                '                                </div>');

        }

        //Demo
        layui.use('form', function () {
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function (data) {
                return false;
            });
            // //执行一个laydate实例
            // laydate.render({
            //     elem: '#birthday' //指定元素
            //     ,type: 'date'
            // });
        });
//下一步点击事件
        function btn_next() {
            var oldCode = $("#oldCode").val();
            $.ajax({
                url: "/user/ChangeEmailCheckCode",
                data:  sendEncrypt(JSON.stringify(
                    {"code": oldCode}
                )),
                dataType: "json",
                async: false,
                contentType: "application/json",
                success: function (data) {
                    data=JSON.parse(receiveEncrypt(data));
                    if (data["result"] == "ok") {
                        layer.msg('邮箱验证成功', {time: 1000}, function () {
                            unhasEmailInit();
                        });
                    } else if (data["result"] == "codeError") {
                        layer.msg('验证码错误,你还有：'+data["changeEmailAuthCodeCount"]+'次机会！', {time: 1000}, function () {
                            $("#oldCode").val('')
                        });
                    } else if (data["result"] == "maxCode") {
                        layer.msg('输入次数达到上限，请重新发送验证码！', {time: 1000}, function () {

                        });
                    } else if (data["result"] == "noCode") {
                        layer.msg('请重新发送验证码！', {time: 1000}, function () {

                        });
                    }else if (data["result"] == "noSession") {
                        layer.msg('登录失效，请重新登录！', {time: 1000}, function () {
                            window.location="login";
                        });
                    }else {
                        layer.msg('系统错误', {time: 1000}, function () {
                        });
                    }

                },
                type: "post"
            });
        }
        function sendOldEmail(){
            var email="[[${email}]]";
            var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
            if(!reg.test(email)){ //正则验证不通过，格式不对
                layer.msg('邮箱格式不正确!',{time:800},function(){
                });
            }else{
                $.ajax({
                    url: "/user/changeEmailAuthCode",
                    data:  sendEncrypt(JSON.stringify(
                        {"email": email,"type":"old"}
                    )),
                    dataType: "json",
                    async: false,
                    contentType: "application/json",
                    success: function (data) {
                        data=JSON.parse(receiveEncrypt(data));
                        if (data["result"] == "ok") {
                            layer.msg('发送成功', {time: 1000}, function () {

                            });
                        } else if (data["result"] == "fail") {
                            layer.msg('发送失败', {time: 1000}, function () {

                            });
                        } else if (data["result"] == "unexit") {
                            layer.msg('该邮箱未被注册，请注册后在进行此操作', {time: 1000}, function () {

                            });
                        } else {
                            layer.msg('系统错误', {time: 1000}, function () {
                            });
                        }

                    },
                    type: "post"
                });
            }
        }
        function sendNewEmail(){
            var email=$("#newEmail").val();
            console.log(email);
            var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
            if(!reg.test(email)){ //正则验证不通过，格式不对
                layer.msg('邮箱格式不正确!',{time:800},function(){
                });
            }else{
                $.ajax({
                    url: "/user/changeEmailAuthCode",
                    data: 	 sendEncrypt(JSON.stringify(
                        {"email": email,"type":"new"}
                    )),
                    dataType: "json",
                    async: false,
                    contentType: "application/json",
                    success: function (data) {
                        data=JSON.parse(receiveEncrypt(data));
                        if (data["result"] == "ok") {
                            layer.msg('发送成功', {time: 1000}, function () {

                            });
                        } else if (data["result"] == "fail") {
                            layer.msg('发送失败', {time: 1000}, function () {

                            });
                        } else if (data["result"] == "exit") {
                            layer.msg('该邮箱已被注册，无法绑定！', {time: 1000}, function () {

                            });
                        } else {
                            layer.msg('系统错误', {time: 1000}, function () {
                            });
                        }

                    },
                    type: "post"
                });
            }
        }
        function commit() {
            var newCode = $("#newCode").val();
            $.ajax({
                url: "/user/ChangeEmailCheckCode",
                data:sendEncrypt(JSON.stringify({
                    "code": newCode
                })),

                dataType: "json",
                async: false,
                contentType: "application/json",
                success: function (data) {
                    data=JSON.parse(receiveEncrypt(data));
                    var newEmail=$("#newEmail").val();
                    if (data["result"] == "ok") {
                        $.ajax({
                            url: "/user/ChangeEmail",
                            data:sendEncrypt(JSON.stringify({
                                "newEmail": newEmail
                            })),

                            dataType: "json",
                            async: false,
                            contentType: "application/json",
                            success: function (data) {
                                data=JSON.parse(receiveEncrypt(data));
                                if (data["result"] == "ok") {
                                    layer.msg('邮箱绑定成功！', {time: 1000}, function () {
                                        window.location="accountSecurity";
                                    });
                                } else if (data["result"] == "fail") {
                                    layer.msg('邮箱绑定失败，请重试！', {time: 1000}, function () {
                                        window.location="accountSecurity";
                                    });
                                }else if (data["result"] == "noSession") {
                                    layer.msg('登录失效，请重新登录！', {time: 1000}, function () {
                                        window.location="login";
                                    });
                                }else {
                                    layer.msg('系统错误', {time: 1000}, function () {
                                    });
                                }

                            },
                            type: "post"
                        });
                    } else if (data["result"] == "codeError") {
                        layer.msg('验证码错误,你还有：'+data["changeEmailAuthCodeCount"]+'次机会！', {time: 1000}, function () {
                            $("#oldCode").val('')
                        });
                    } else if (data["result"] == "maxCode") {
                        layer.msg('输入次数达到上限，请重新发送验证码！', {time: 1000}, function () {

                        });
                    } else if (data["result"] == "noCode") {
                        layer.msg('请重新发送验证码！', {time: 1000}, function () {

                        });
                    }else if (data["result"] == "noSession") {
                        layer.msg('登录失效，请重新登录！', {time: 1000}, function () {
                            window.location="login";
                        });
                    }else {
                        layer.msg('系统错误', {time: 1000}, function () {
                        });
                    }

                },
                type: "post"
            });
        }
    </script>

</head>
<body>

 <input type="hidden" id="cartIdNull" th:value="${session.cartIsNull}">
 <header id="pc-header">
     <div class="BHeader">
         <div class="yNavIndex">
             <ul class="BHeaderl">
                 <li><a th:if="${session.userId}==null"  th:href="@{/login}">请登录</a></li>
                 <li class="headerul" th:if="${session.userId}==null">|</li>
                 <li><a th:if="${session.userId}==null" th:href="@{/register}">免费注册</a></li>
                 <li class="headerul" th:if="${session.userId}==null">|</li>
                 <li><a th:href="@{/myOrder?pageNum=1&pageSize=5}" th:if="${session.userId}!=null">我的订单</a></li>
                 <li class="headerul" th:if="${session.userId}!=null">|</li>
                 <li><a th:href="@{/myCollect?pageNum=1&pageSize=8}" th:if="${session.userId}!=null">我的收藏</a></li>
                 <li class="headerul" th:if="${session.userId}!=null">|</li>
                 <li id="pc-nav" class="menu" th:if="${session.userId}!=null" ><a th:href="@{#}" class="tit">我的淘淘</a>
                     <div class="subnav">
                         <a th:href="@{#}">账户安全</a>
                         <a th:href="@{/myAddress}">地址管理</a>
                         <a th:href="@{/myEvaluate?pageNum=1&pageSize=5}">我的评价</a>
                         <a th:href="@{/viewHistory?pageNum=1&pageSize=5}">浏览记录</a>
                     </div>
                 </li>
                 <li class="headerul" th:if="${session.userId}!=null">|</li>
                 <li th:if="${session.userId}!=null">
                     <a th:text="${session.userName}"></a>
                 </li>
                 <li th:if="${session.userId}!=null">
                     <img th:src="'/myFile/img/userHeadPic/'+${session.userHead}+''" onclick="javascript:window.location='myInfo'"  style=" width:30px;height:30px;">
                     <a href="javascript:logout()" style="float: right;">退出</a>
                 </li>
             </ul>
         </div>
     </div>
     <div class="container clearfix"style="padding:20px 0 20px ">
         <div class="header-logo fl" ><h1><a th:href="@{/index}" style="color:#ea4949;">
             <img th:src="@{/myFile/imgold/icon/logo1.png}"style="width:100px;height:80px;"><strong>淘淘商城</strong></a></h1>
         </div>
         <div class="head-form fl">
             <form class="clearfix">
                 <input type="text" class="search-text" id="searchKey" autocomplete="off" placeholder="手机">
                 <button type="button" class="button" onclick="searchToPage();">搜索</button>
             </form>
             <div class="words-text clearfix">
                 <a th:href="@{#}" class="red">1元秒爆</a>
                 <a th:href="@{#}">低至五折</a>
                 <a th:href="@{#}">农用物资</a>
                 <a th:href="@{#}">买一赠一</a>
                 <a th:href="@{#}">佳能相机</a>
                 <a th:href="@{#}">稻香村月饼</a>
                 <a th:href="@{#}">服装城</a>
             </div>
         </div>
         <div class="header-cart fr" th:if="${session.userId}!=null">
             <a  th:href="@{/myCart?pageNum=1&pageSize=5}" target="_blank"
                 style="height:30px;width:30px;float:right;margin-right:50px;"><img
                     id="test" src="../myFile/imgold/icon/car.png"></a>
             <i th:if="${session.cartIsNull}=='notNull'" class="head-amount" id="cartCountExist" th:text="${session.cartAllCount}"></i>
             <i th:if="${session.cartIsNull}=='null'" class="head-amount" id="cartCountUnExist">0</i>
         </div>
     </div>
 </header>

<div class="containers"><div class="pc-nav-item"><a th:href="@{/index}">首页</a> &gt; <a th:href="@{#}">我的淘淘 </a> &gt; <a th:href="@{#}">账户安全</a> &gt; <a th:href="@{#}">修改邮箱</a></div></div>

 <section id="member">
     <div class="member-center clearfix">
         <div class="member-left fl">
             <div class="member-apart clearfix">
                 <div class="fl"><a th:href="@{#}"><img th:src="'/myFile/img/userHeadPic/'+${session.userHead}+''" onclick="javascript:window.location='myInfo'" ></a></div>
                 <div class="fl">
                     <p>昵称：</p>
                     <p><a th:href="@{/#}" th:text="${session.userName}"></a></p>
                 </div>
             </div>
             <div class="member-lists">
                 <dt>我的淘淘</dt>
                 <dd><a th:href="@{/myOrder?pageNum=1&pageSize=5}">我的订单</a></dd>
                 <dd><a th:href="@{/myCollect?pageNum=1&pageSize=8}">我的收藏</a></dd>
                 <dd class="cur"><a th:href="@{/accountSecurity}">账户安全</a></dd>
                 <dd><a th:href="@{/myEvaluate?pageNum=1&pageSize=5}">我的评价</a></dd>
                 <dd><a th:href="@{/myAddress}">地址管理</a></dd>
                 <dd><a th:href="@{/viewHistory?pageNum=1&pageSize=5}">浏览记录</a></dd>
                 </dl>
                 <dl>
                     <dt>客户服务</dt>

                     <dd><a th:href="@{/request}">退货/退款记录</a></dd>
                 </dl>
                 <dl>
                     <dt>我的消息</dt>
                     <dd ><a th:href="@{#}">商城快讯</a></dd>
                     <dd><a th:href="@{#}">帮助中心</a></dd>
                 </dl>
             </div>
         </div>
        <div class="member-right fr">
            <div class="member-head" style="background:#fff">
                <div class="member-heels"><h2 style="color:black">修改邮箱</h2></div>
            </div>
            <div class="member-border">
                <div class="member-secure clearfix">
                    <div class="member-extent fl">
                        <form class="layui-form" action="" >

                            <div id="changeHtml">

                            </div>

<!--                            <div class="layui-form-item">-->
<!--                                <div class="layui-input-block">-->
<!--                                    <button onclick="commit()" class="layui-btn layui-btn-normal" lay-submit-->
<!--                                            lay-filter="formDemo">立即提交-->
<!--                                    </button>-->

<!--                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
<!--                                    <button type="button" class="layui-btn layui-btn-primary" onclick="textin()">1-->
<!--                                    </button>-->
<!--                                </div>-->
<!--                            </div>-->
                        </form>

                    </div>

                </div>
            </div>
        </div>
    </div>
</section>
<!-- 商城快讯 End -->

<!--- footer begin-->
<div class="aui-footer-bot">
    <div class="time-lists aui-footer-pd clearfix">
        <div class="aui-footer-list clearfix">
            <h4>
                <span><img th:src="@{/myFile/imgold/icon/icon-d1.png}"></span>
                <em>消费者权益</em>
            </h4>
            <ul>
                <li><a th:href="@{#}">保障范围 </a></li>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>
                <span><img th:src="@{/myFile/imgold/icon/icon-d2.png}"></span>
                <em>新手上路</em>
            </h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>
                <span><img th:src="@{/myFile/imgold/icon/icon-d3.png}"></span>
                <em>保障正品</em>
            </h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>
                <span><img th:src="@{/myFile/imgold/icon/icon-d1.png}"></span>
                <em>消费者权益</em>
            </h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
    </div>
    <div style="border-bottom:1px solid #dedede"></div>
    <div class="time-lists aui-footer-pd time-lists-ls clearfix">
        <div class="aui-footer-list clearfix">
            <h4>购物指南</h4>
            <ul>
                <li><a th:href="@{#}">保障范围 </a></li>
                <li><a th:href="@{#}">购物流程</a></li>
                <li><a th:href="@{#}">会员介绍 </a></li>
                <li><a th:href="@{#}">生活旅行</a></li>
                <li><a th:href="@{#}"> 常见问题 </a></li>
                <li><a th:href="@{#}"> 联系客服购物指南 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>特色服务</h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>帮助中心</h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
        <div class="aui-footer-list clearfix">
            <h4>新手指导</h4>
            <ul>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">退货退款流程</a></li>
                <li><a th:href="@{#}">服务中心 </a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}">服务中心</a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
                <li><a th:href="@{#}"> 更多特色服务 </a></li>
            </ul>
        </div>
    </div>
</div>
<!-- footer End -->
</body>
</html>